package com.xinhua.control;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.xinhua.entity.Courses;
import com.xinhua.entity.Major;
import com.xinhua.entity.Period;
import com.xinhua.entity.Student;
import com.xinhua.entity.SurveyContent;
import com.xinhua.entity.SurveyDetail;
import com.xinhua.entity.SurveyItem;
import com.xinhua.entity.Teacher;
import com.xinhua.service.CoursesService;
import com.xinhua.service.MajorService;
import com.xinhua.service.PeriodService;
import com.xinhua.service.StudentService;
import com.xinhua.service.SurveyContentService;
import com.xinhua.service.SurveyDetailService;
import com.xinhua.service.SurveyItemService;
import com.xinhua.service.TeacherService;

@RestController
public class QueryManager {
	private List<SurveyItem> sitem;
	private List<Major> major;
	private List<Courses> course;
	private List<Teacher> teach;
	private List<SurveyDetail> sdetail;
	private List<Student> student;
	private List<Period> periods;
	private List<SurveyContent> surconts;

	@Autowired
	private SurveyItemService sis;
	@Autowired
	private SurveyContentService scs;
	@Autowired
	private MajorService ms;
	@Autowired
	private CoursesService cs;
	@Autowired
	private TeacherService ts;
	@Autowired
	private SurveyDetailService sds;
	@Autowired
	private StudentService ss;
	@Autowired
	private PeriodService ps;
	
    @RequestMapping("/SetQueryHtml")
    public void setProHtml(HttpServletRequest req,@RequestParam("queryid")String queryid){
    	HttpSession session=req.getSession(true);
    	session.setAttribute("queryid", queryid);
    }
    
    @RequestMapping("/GetQueryHtml")
    public String getQueryHtml(HttpServletRequest req){
		HttpSession session=req.getSession();
		String queryid=(String) session.getAttribute("queryid");
		String queryText=null;
		switch (queryid) {
		case "0":
			queryText=queryid;
			break;
		case "1":
			queryText=queryid;
			break;
		case "2":
			queryText=queryid;
			break;
		case "3":
			queryText=queryid;
			break;
		case "4":
			queryText=queryid;
			break;
		case "5":
			queryText=queryid;
			break;
		case "6":
			queryText=queryid;
			break;
		default:
			break;
		}
    	return queryText;
    }
    
   /* @RequestMapping("/GetMSTeacher")
    public List<Teacher> getTeacher(HttpServletRequest req,@RequestParam("teachername")String teachername,@RequestParam("teachersex")String teachersex,
    		                         @RequestParam("teacherage")String teacherage,@RequestParam("teacherduty")String teacherduty){
    	List<Teacher> teachers=new ArrayList<>();
    	Teacher teacher=ts.getOneTeacher(teachername);
    	teachers.add(teacher);
    	return teachers;
    }*/
    
    @RequestMapping("/GetMSStudent")
    public List<Student> getStudent(){
		student=ss.getStudent();
    	return student;
    }
    
    @RequestMapping("/GetMSMajor")
    public List<Major> getMajor(){
		major=ms.getMajor();
    	return major;
    }
    
    @RequestMapping("/GetMSCourse")
    public List<Courses> getCourse(){
		course=cs.getCourse();
    	return course;
    }
    
    @RequestMapping("/GetMSSurItem")
    public List<SurveyItem> getSurItem(){
		sitem=sis.getSurveyItem();
    	return sitem;
    }
    
    @RequestMapping("/GetMSSurCon")
    public List<SurveyContent> getSurCon(){
		surconts=scs.getSurveyContent();
    	return surconts;
    }
    
    @RequestMapping("/GetMSSurResult")
    public List<SurveyDetail> getSurResult(){
		sdetail=sds.getSurveyDetail();
    	return sdetail;
    }
    
}
